from flask import request

from core.login import Login
from core.users import Users
from tools import md5


def querySalers():
    """
       获取营业员信息
       :return: 营业员信息
       """

    user = Users()
    ret = user.getSalers()

    return ret

def queryusers():
    """
       获取记住的用户
       :return: 记住的用户信息
       """
    users = Users()
    arrs = users.getUserInfo()
    arr = users.getIsUserRem()
    data = {}
    data["users"] = arrs
    data["isuserrem"] = arr
    #  返回
    ret = {}
    ret["code"] = 0
    ret["data"] = data

    return ret

def login(**kwargs):
    """
     登录
    :return: 登录的用户信息
    """
    requestJson = request.get_json(True)
    print(requestJson)
    name = requestJson["name"];
    password = requestJson["password"]
    storeID = requestJson["storeid"]
    isUsername = requestJson["isUsername"]
    isPassword = requestJson["isPassword"]

    # 判断32位已加密
    if len(password) != 32:
        password = md5.genearteMD5(password)

    login = Login()
    ret = login.login(name, password, storeID, isUsername, isPassword)

    return ret
